package com.fuhao.activeMQ.listener;

import com.fuhao.model.Mail;
import org.springframework.transaction.annotation.Transactional;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;

/**
* @Description:    第二个消费者
* @Author:         RichZhang
*/
public class QueueListener2 implements MessageListener {
//	@Transactional
	@Override
	public void onMessage(Message message) {

		System.out.println("进来消费了");
		//int i = 1/0;//测试重试机制是否成功
		ObjectMessage objectMessage = (ObjectMessage) message;
		try {
			message.acknowledge();
			Mail mail = (Mail) objectMessage.getObject();
			System.out.println("queue:消费者2收到的信息：" +mail);
//			message.acknowledge();
		} catch (JMSException e) {
			e.printStackTrace();
		}
	}
}
